
Partial Class Case_ChangeStatus
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        If Not Me.IsPostBack Then

            Dim statusHistoryId As Integer = Convert.ToInt32(Request("id"))
            Dim statusHistory As Cdm.DataCore.Entities.ParticipantStatusHistory
            statusHistory = Cdm.DataCore.Entities.ParticipantStatusHistory.Retrieve(statusHistoryId)

            Me.StatusDropDownList.DataSource = Cdm.DataCore.LookupTables.LuCaseStatus.ListAll()
            Me.StatusDropDownList.DataTextField = "Description"
            Me.StatusDropDownList.DataValueField = "CaseStatusId"
            Me.StatusDropDownList.DataBind()
            Me.StatusDropDownList.Value = statusHistory.CaseStatusId.ToString()

            Me.StatusReasonDropDownList.DataSource = Cdm.DataCore.CaseNotes.CaseStatusReason.ListByCaseStatus(statusHistory.CaseStatusId)
            Me.StatusReasonDropDownList.DataTextField = "Description"
            Me.StatusReasonDropDownList.DataValueField = "CaseStatusReasonId"
            Me.StatusReasonDropDownList.DataBind()
            Me.StatusReasonDropDownList.Editable = True

        End If

        Me.StatusDropDownList.Editable = False

    End Sub

    Protected Sub SaveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveButton.Click

        Dim statusHistoryId As Integer = Convert.ToInt32(Request("id"))
        Dim statusHistory As Cdm.DataCore.Entities.ParticipantStatusHistory
        statusHistory = Cdm.DataCore.Entities.ParticipantStatusHistory.Retrieve(statusHistoryId)

        statusHistory.CaseStatusReasonId = Convert.ToInt32(Me.StatusReasonDropDownList.Value)
        statusHistory.Comments = Me.CommentsTextbox.Text
        If IsDate(Me.ReinstatementDate.Value) Then
            statusHistory.EstimatedReturnDate = Convert.ToDateTime(Me.ReinstatementDate.Value)
        End If
        statusHistory.Persist()
        Response.Redirect("casePersonal.aspx")

    End Sub

End Class
